#include<head.h>

void *pth(void *arg)
{
    int i = 0;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);//设置线程取消状态为不可取消
    while(1)
    {
        printf("pth is running %d\n",i++);
        sleep(1);
    }
    return NULL;
}

int main(int argc, char const *argv[])
{
    pthread_t tid;
    int ret = pthread_create(&tid,NULL,pth,NULL);
    if(ret != 0)
    {
        perror("pthread_create");
        return -1;
    }
    sleep(3);
    pthread_cancel(tid);
    pthread_detach(tid);
    while(1)
    {
        
    }
    return 0;
}
